package gervosou;

import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class VueConsultComptesSociete extends Vue {
	private Societe _societe;
	
	private JFrame frmVueConsultComptesSociete;
	
	private JTextField textFieldNom_soc;
	
	private JTextArea textAreaComptesSoc;
	
	private JLabel lblNomDeLa;
	
	private JButton btnRechercher;
	private JButton btnAnnuler;
	private JButton btnQuitter;
	
	private JScrollPane scrollPaneCpts_soc;
	
	private JPanel panel;
	
	public VueConsultComptesSociete (Controleur c) {
		super (c);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 418, 291);
		panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		lblNomDeLa = new JLabel("Nom de la societe :");
		lblNomDeLa.setBounds(59, 27, 118, 15);
		panel.add(lblNomDeLa);
		
		textFieldNom_soc = new JTextField();
		textFieldNom_soc.setBounds(244, 25, 114, 19);
		panel.add(textFieldNom_soc);
		textFieldNom_soc.setColumns(10);
		
		btnRechercher = new JButton("Rechercher");
		btnRechercher.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String nom = textFieldNom_soc.getText();
				// liaison de la vue avec l'objet observe
				setSociete (getControleur().rechSociete2(nom));
			}
			});
		btnRechercher.setBounds(70, 75, 107, 25);
		panel.add(btnRechercher);
		
		
		
		btnAnnuler = new JButton("Annuler");		
		btnAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueConsultComptesSociete.this);}
	});
		btnAnnuler.setBounds(244, 75, 107, 25);
		panel.add(btnAnnuler);
		
		scrollPaneCpts_soc = new JScrollPane();
		scrollPaneCpts_soc.setBounds(59, 131, 299, 68);
		panel.add(scrollPaneCpts_soc);
		
		textAreaComptesSoc = new JTextArea();
		textAreaComptesSoc.setEditable(false);
		scrollPaneCpts_soc.setColumnHeaderView(textAreaComptesSoc);
		
		btnQuitter = new JButton("Quitter");
		btnQuitter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueConsultComptesSociete.this);}
	});
		btnQuitter.setBounds(150, 211, 107, 25);
		panel.add(btnQuitter);
	}
	
	private Societe getSociete() {
		return _societe;
	}
	
	private void setSociete(Societe soc) {
		 _societe = soc;
	}
	
	public void alimente(Societe soc) {
		textAreaComptesSoc.setText("");
		for (CompteSociete cs : soc.getComptes()) {
			textAreaComptesSoc.append( "numero " + String.valueOf(cs.getNumCompte()) + " solde " + String.valueOf(cs.getSolde()) + "\n");
		}
	}
	}
